05 / 19

What is the difference between a String and a Character Array?

String vs Character Array

  1. 1

    A String provides higher-level operations such as searching, slicing, comparison, and concatenation.

  2. 2

    A character array provides direct mutable access to individual characters.

  3. 3

    Java String objects are immutable.

  4. 4

    A char[] can be modified after creation.

  5. 5

    Character arrays can sometimes be preferable when sensitive character data must be explicitly cleared from memory, although memory clearing has platform-specific limitations.

Difficulty: 1/10

Follow-up Questions

  • Why is Java String immutable?
  • When would you use char[] instead of String?